package cn.seocoo.platform.web.controller.search;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.seocoo.platform.common.annotation.Log;
import cn.seocoo.platform.common.enums.BusinessType;
import cn.seocoo.platform.search.domain.SearchRecord;
import cn.seocoo.platform.search.service.ISearchRecordService;
import cn.seocoo.platform.common.core.controller.BaseController;
import cn.seocoo.platform.common.core.page.TableDataInfo;
import cn.seocoo.platform.common.core.domain.AjaxResult;
import cn.seocoo.platform.common.utils.poi.ExcelUtil;

/**
 * 用户搜索记录 信息操作处理
 * 
 * @author wujian
 * @date 2019-12-25
 */
@Controller
@RequestMapping("/search/searchRecord")
public class SearchRecordController extends BaseController
{
    private String prefix = "search/searchRecord";
	
	@Autowired
	private ISearchRecordService searchRecordService;
	
	@RequiresPermissions("search:searchRecord:view")
	@GetMapping()
	public String searchRecord()
	{
	    return prefix + "/searchRecord";
	}
	
	/**
	 * 查询用户搜索记录列表
	 */
	@RequiresPermissions("search:searchRecord:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SearchRecord searchRecord)
	{
		startPage();
        List<SearchRecord> list = searchRecordService.selectSearchRecordList(searchRecord);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出用户搜索记录列表
	 */
	@RequiresPermissions("search:searchRecord:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SearchRecord searchRecord)
    {
    	List<SearchRecord> list = searchRecordService.selectSearchRecordList(searchRecord);
        ExcelUtil<SearchRecord> util = new ExcelUtil<SearchRecord>(SearchRecord.class);
        return util.exportExcel(list, "searchRecord");
    }
	
	/**
	 * 新增用户搜索记录
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存用户搜索记录
	 */
	@RequiresPermissions("search:searchRecord:add")
	@Log(title = "用户搜索记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SearchRecord searchRecord)
	{		
		return toAjax(searchRecordService.insertSearchRecord(searchRecord));
	}

	/**
	 * 修改用户搜索记录
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		SearchRecord searchRecord = searchRecordService.selectSearchRecordById(id);
		mmap.put("searchRecord", searchRecord);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存用户搜索记录
	 */
	@RequiresPermissions("search:searchRecord:edit")
	@Log(title = "用户搜索记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SearchRecord searchRecord)
	{		
		return toAjax(searchRecordService.updateSearchRecord(searchRecord));
	}
	
	/**
	 * 删除用户搜索记录
	 */
	@RequiresPermissions("search:searchRecord:remove")
	@Log(title = "用户搜索记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(searchRecordService.deleteSearchRecordByIds(ids));
	}
	
}
